-
Notifications
You must be signed in to change notification settings - Fork 832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(tracer): reduce overhead of attribute sanitization #4558
Conversation
5d5aca6
to
7158e6a
Compare
7158e6a
to
519e021
Compare
if (typeof attributes !== 'object' || attributes == null) { | ||
return out; | ||
} | ||
|
||
for (const [key, val] of Object.entries(attributes)) { | ||
for (const key in attributes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some environments (runtimes) where the usage of x in y
can cause issues where the only additional fix is to also use Object.hasOwnProperty
so this may have unexpected (endless looping) consequences.
It's been a while since I saw this previously, but (from memory) it is caused by a 3rd party library adding stuff to Object to support the runtime environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to add Object.hasOwnProperty
then, I think allocations is more of a problem than sheer performance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added propertyIsEnumerable check
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4558 +/- ##
=======================================
Coverage 92.83% 92.84%
=======================================
Files 328 328
Lines 9486 9498 +12
Branches 2035 2043 +8
=======================================
+ Hits 8806 8818 +12
Misses 680 680
|
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
This PR was closed because it has been stale for 14 days with no activity. |
Which problem is this PR solving?
OTEL is producing too much allocations
Fixes # (issue)
Short description of the changes
Added possibility for sanitizeAttributes to operate in place on provided object. Remove Object.entries and do prevent copying already allocated copies of arrays
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
After:
create spans (10 attributes) x 702,092 ops/sec ±1.32% (88 runs sampled)
create spans (10 attributes) passed as options x 603,744 ops/sec ±0.57% (97 runs sampled)
BatchSpanProcessor process span x 652,096 ops/sec ±0.97% (93 runs sampled)
Before:
create spans (10 attributes) x 691,170 ops/sec ±1.13% (94 runs sampled)
create spans (10 attributes) passed as options x 291,230 ops/sec ±0.54% (99 runs sampled)
BatchSpanProcessor process span x 645,159 ops/sec ±0.97% (95 runs sampled)
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: